package itheima06;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;

/**
 * @author xxx
 * @date 2020/12/25 21:47
 * @description
 */
public class Test {
    public static void main(String[] args) {
        //获取第一个第二个对象的流
        List<String> o = new ArrayList<>();
        o.add("迪丽热巴");
        o.add("宋远桥");
        o.add("苏星河");
        o.add("老子");
        o.add("庄子");
        o.add("孙子");
        o.add("洪七公");

        Stream<String>stream=o.stream();

        //选出只有两个汉字的名字
        Stream<String>stream1=stream.filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.length()==2;
            }
        });

        //保留前两个，最后都转化为lambda表达式


        Stream<String>stream2=stream1.limit(2);

        List<String> t = new ArrayList<>();
        t.add("古力娜扎");
        t.add("张无忌");
        t.add("张三丰");
        t.add("赵丽颖");
        t.add("张二狗");
        t.add("张天爱");
        t.add("张三");

        Stream<String>stream3=t.stream();

        //保留姓张的
        Stream<String>stream4=stream3.filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.startsWith("张");
            }
        });



        //跳过前两个
        Stream<String>stream5=stream4.skip(2);
        //合并
        Stream<String>stream6=Stream.concat(stream2,stream5);
        //展示

         stream6.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });


    }
}
